﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;

namespace CommonLib
{
    public abstract class FetcherConfigBaseRec
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private const string nameAttrString = "name";
        private const string typeAttrStr = "type";
        private const string activeAttrString = "active";
        
        public string FetcherType { get { return _FetcherType; } }
        public string FetcherName { get { return _FetcherName; } }
        public bool  isActive { get { return _isActive; } }


        public bool LoadBasicConfiguration(XmlNode fetcherNode)
        {
            bool isValidConfig = true;

            XmlAttribute xmlAttr = null;

            #region READ_BASICS

            // read fetcher Name Attribute 
            xmlAttr = fetcherNode.Attributes[nameAttrString];
            if (xmlAttr == null)
            {
                log.DebugFormat("AttributeMissing : " + nameAttrString + " :  For fetcher Record ");
                return false;
            }
            _FetcherName = xmlAttr.Value;

            log.DebugFormat("Name: " + FetcherName);


            xmlAttr = fetcherNode.Attributes[typeAttrStr];
            if (xmlAttr == null)
            {
                log.FatalFormat("AttributeMissing : " + typeAttrStr + " :  For fetcher Record ");
                return false;
            }

            _FetcherType = xmlAttr.Value;

            // Read Active String 
            _isActive = true;
            xmlAttr = fetcherNode.Attributes[activeAttrString];
            if (xmlAttr != null)
            {
                _isActive = System.Convert.ToBoolean(xmlAttr.Value);
            }

            #endregion

            return isValidConfig;

        }


        protected  string _FetcherName;
        protected  string _FetcherType;
        protected bool _isActive;
    }

    public  interface  FetcherInterface
    {
         FetcherConfigBaseRec getConfiguration(XmlNode fetcherNode);
         Object crawlForData(FetcherConfigBaseRec configRec);
         
    }
}
